<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\service\PostService;
use cmf\controller\HomeBaseController;
use think\facade\Db;

class IndexController extends HomeBaseController
{
    public function index()
    {
        $demo = Db::name('demo')->order('list_order DESC')->limit(10)->select();
        $category =  Db::name('portal_category')->where('delete_time',0)->field('name,id')->select()->toArray();
        if (!empty($category)){
            foreach($category as &$item){
                $item['child'] = Db::name('portal_category_post')
                    ->alias('cp')
                    ->leftJoin('portal_post p','p.id = cp.post_id')
                    ->where('cp.category_id',$item['id'])
                    ->field('p.post_title,p.id')
                    ->limit(5)
                    ->select()->toArray();
            }
        }
        $this->assign('posts',$category);
        $this->assign('demo',$demo);
        return $this->fetch(':index');
    }

    public function about()
    {
        return $this->fetch(':about');
    }


    public function contact()
    {
        return $this->fetch(':contact');
    }
    
    
}
